<template>
  <div>
    <div class="title">
      <el-row>
        <el-col :span="1" style="width: 50px;">
          <span style="color:#757575;">位置 : </span>
        </el-col>
        <el-col :span="20">
          <span class="textactive">时间字典值</span>
        </el-col>
      </el-row>
    </div>
    <div class="posttable">
      <el-row type="flex" justify-content="center" style="padding-top: 20px;margin-left:65px">
        <el-col :span="6" class="time">
          <el-col class="timetitle">
          <p>星级开始时间(前一天)</p>
          </el-col>
          <el-col class="gut"></el-col>
          
          <el-col class="timecontent">
            <el-row type="flex" justify="center">
              <el-col :span="8" style="margin-top: 20px;">
              <clock :time="retime"></clock>
              </el-col>
            
            </el-row>
            <el-row type="flex" justify="center">
              <el-col :span="10" style="margin-top: 20px;">
                <el-time-picker
                  v-model="stime1"
                  placeholder="开始时间"
                  value-format="HH:mm"
                  format="HH:mm"
                  @change="changeStratTime1"
                >
                </el-time-picker>
              </el-col>
            </el-row>
          </el-col>
        
        
        </el-col>

        <el-col :span="6" class="time">
          <el-col class="timetitle">
          <p>星级置灰时间(第二天)</p>
          </el-col>
          <el-col class="gut"></el-col>
          
          <el-col class="timecontent">
            <el-row type="flex" justify="center">
              <el-col :span="8" style="margin-top: 20px;">
                <clock :time="time"></clock>
              </el-col>
            
            </el-row>
            <el-row type="flex" justify="center">
              <el-col :span="10" style="margin-top: 20px;">
                <el-time-picker
                  v-model="time1"
                  placeholder="开始时间"
                  value-format="HH:mm"
                  format="HH:mm"
                  @change="changeStratTime"
                >
                </el-time-picker>
              </el-col>
            </el-row>
          </el-col>
        
        
        </el-col>
        <el-col :span="6" class="time">
          <el-col class="timetitle">
            <p>选择专员置灰时间</p>
          </el-col>
          <el-col class="gut"></el-col>
          <el-col class="timecontent">
            <el-row type="flex" justify="center">
              <el-col :span="8" style="margin-top: 20px;">
                <clock :time="time2"></clock>
              </el-col>
            
            </el-row>
            <el-row type="flex" justify="center">
              <el-col :span="10" style="margin-top: 20px;">
                <el-time-picker
                  v-model="time3"
                  placeholder="结束时间"
                  value-format="HH:mm"
                  format="HH:mm"
                  @change="changeEndTime"
                >
                </el-time-picker>
              </el-col>
            </el-row>
          </el-col>
        </el-col>
      </el-row>
    </div>
    
  </div>

</template>

<script>
  import Clock from 'vue-clock2';
  import axios from 'axios'
  import qs from 'qs'
  export default {
    name: "timeValue",
    data() {
      return {
        time: '',
        stime1:'',
        time1: '',
        time2: '',
        time3: '',
        retime:'',
        startTime: '',
        endTime: '',
        id : ''
      }
    },
    components: {
      Clock,
    },
    created(){
     this.getData();
    },
    methods: {
      //获取当前的时间数据
      getData(){
        axios.post(this.url + '/timedictionary/getTime').then(res => {
          this.unlogin(res.data.code);
          if(res.data.code == 200){
            for(var i = 0 ;i < res.data.data.length;i++){
              this.time = res.data.data[0].starclassTime;
              this.stime1 = res.data.data[0].starafterTime;
              this.time1 = res.data.data[0].starclassTime;
              this.time2 = res.data.data[0].comeTime;
              this.time3 = res.data.data[0].comeTime;
              this.id = res.data.data[0].id;
            }
          }
        })
      },
      //改变星级开始的时间
      changeStratTime1(item) {
        this.stime1= item;
        this.retime = item;
        axios.post(this.url + '/timedictionary/updateTime',qs.stringify({
          starclassTime : this.time1,
          comeTime : this.time3,
          starafterTime:this.stime1,
          id : this.id
        })).then(res => {
          this.unlogin(res.data.code);
          if(res.data.code){
            this.getData();
          }
        })
      },
      //改变星级置灰的时间
      changeStratTime(item) {
        this.time1= item;
        this.time = item;
        
        axios.post(this.url + '/timedictionary/updateTime',qs.stringify({
          starclassTime : this.time1,
          comeTime : this.time3,
          starafterTime:this.stime1,
          id : this.id
        })).then(res => {
          this.unlogin(res.data.code);
          if(res.data.code){
            this.getData();
          }
        })
      },
      //改变专员置灰的时间
      changeEndTime(item) {
        this.time2= item;
        this.time3 = item;
        axios.post(this.url + '/timedictionary/updateTime',qs.stringify({
          starclassTime : this.time1,
          comeTime : this.time3,
          starafterTime:this.stime1,
          id : this.id
        })).then(res => {
         this.unlogin(res.data.code);
          if(res.data.code){
            this.getData();
          }
        })
      }
    },
  }
</script>

<style scoped>
  .title {
    background-color: #fff;
    height: 40px;
    line-height: 40px;
    font-size: 14px;
    padding-left: 20px;
    margin-top: 6px;
    margin-bottom: 6px;
  }
  
  .textactive {
    color: #1099ff;
  }
  
  .posttable {
    min-height: 700px;
    background-color: #fff;
    margin: 0 auto;
  }
  
  .time {
    width: 488px;
    height: 338px;
    border-radius: 12px;
    margin-right: 75px;
  }
  
  .timetitle {
    height: 56px;
    line-height: 56px;
    color: #fff;
    font-size: 24px;
    background-color: #455ca9;
    border-top-left-radius: 20px;
    border-top-right-radius: 20px;
    text-align: center;
  }
  
  .gut {
    height: 5px;
    background-color: #fe6c19;
  }
  
  .timecontent {
    border: 1px solid #4c4eea;
    height: 276px;
    border-top: none;
    border-bottom-left-radius: 20px;
    border-bottom-right-radius: 20px;
  }
</style>
